/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.tln.sys.permissions.dao.impl;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.tln.sys.permissions.dao.PermissionDao;
import com.tln.sys.permissions.model.Permission;

import java.util.List;

@Repository("permissionDao")
@SuppressWarnings("unchecked")
public class PermissionDaoImpl extends com.xjj.core.modules.orm.hibernate.HibernateDao<Permission, Long> implements PermissionDao {
	
	private static final Logger logger = LoggerFactory.getLogger(PermissionDaoImpl.class); 

    /*public Permission getPermission(Long PermissionId) {
        return (Permission)super.get(PermissionId);//(Permission) getSession().get(Permission.class, PermissionId);
    }*/

    public Permission findPermission(String Permissionname) {
        Assert.hasText(Permissionname);
        String query = "from Permission u where u.Permissionname = :Permissionname";
        return (Permission) getSession().createQuery(query).setString("Permissionname", Permissionname).uniqueResult();
    }

   /* public void savePermission(Permission Permission) {
        getSession().save( Permission );
    }*/

    public List<Permission> getAllPermissions() {
    	logger.info("getAllPermissions..........................");
    	logger.info("***********************1*************");
    	//List list = this.findAll();
    	//logger.info("***********************2*************"+list.size());
    	logger.info("************************3************");
    	List list = getSession().createQuery("from Permission order by Permissionname").list();
    	logger.info("size--- "+list.size());
    	logger.info("***********************4*************");
        return list;
    }

    /*public void deletePermission(Long PermissionId) {
        Permission Permission = getPermission(PermissionId);
        if( Permission != null ) {
            getSession().delete(Permission);
        }
    }

    public void updatePermission(Permission Permission) {
        getSession().update(Permission);
    }*/
    
    
    public List find(String hql) {
		return super.find(hql);
	}
    
    public Permission getPermission(Long id) {
		return super.get(id);
	}

}

